#include "lightshader.h"

LightShader::LightShader(QObject *parent)
    :BaseShader(parent)
{
    m_file_vert = ":/light.vert";
    m_file_frag = ":/light.frag";
}

void LightShader::initializeGL()
{
    BaseShader::initializeGL();

    aPos = m_program->attributeLocation("aPos");

    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);

    glGenBuffers(1, &vbo);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

    glVertexAttribPointer(aPos, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), BUFFER_OFFSET(0));

    glEnableVertexAttribArray(aPos);

}

void LightShader::paintGL()
{
    m_program->bind();

    m_program->setUniformValue("projection", projection);
    m_program->setUniformValue("view", view);

    m_program->setUniformValue("lightColor", QVector3D(1.0f, 1.0f, 1.0f));

//    QMatrix4x4 lightPos;
//    lightPos.translate(QVector3D( -1.0f, 1.0f, -1.0f));
//    lightPos.scale(QVector3D(0.2, 0.2, 0.2));

    m_program->setUniformValue("model", pos);

    glDrawArrays(GL_TRIANGLES, 0, 36);

    m_program->release();
}
